package com.dudu.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;

import com.dudu.access.RedisUtil;
import com.dudu.bean.ParamBean;
import com.dudu.model.SendNotice;
import com.dudu.utils.DateUtils;

import core.CoreDao;
import core.db.DBConnectionUtil;

/**
 * 推送语音短信
 * 
 * @author weidong
 * 
 */
public class SendNoticeDao {

    /**
     * 插入推送语音短信信息
     * 
     * @param dao
     * @param sendNotice
     * @author gaoxs
     * @return 成功返回0，失败返回-1
     */
    public int insert(CoreDao dao, SendNotice sendNotice) {
	// 数据库连接
	Connection con = null;
	int result = -1;
	try {
	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 执行sql拼写
	    StringBuffer sql = new StringBuffer("INSERT INTO t_send_notice(meet_ims_id,caller,callee,content,create_time,"
		    + "schedule_send_time,real_send_time,status,chargeNmr,chargeKey," + "note,voice_name,send_count,completeFileName,push_url,"
		    + "tts_content,voice_type,displayNumber,session_id,app_key," + "cust_account,periphery_code,batch_number,mediaName)");
	    sql.append(" VALUES(?,?,?,?,sysdate()," + "?,?,?,?,?," + "?,?,?,?,?," + "?,?,?,?,?," + "?,?,?,?)");
	    // 执行sql
	    List<JSONObject> list = dao.serviceJsonSql(
		    con,
		    sql.toString(),
		    new Object[] { sendNotice.getMeet_ims_id(), sendNotice.getCaller(), sendNotice.getCallee(), sendNotice.getContent(), sendNotice.getSchedule_send_time(),
			    sendNotice.getReal_send_time(), sendNotice.getStatus(), sendNotice.getChargeNmr(), sendNotice.getChargeKey(), sendNotice.getNote(),
			    sendNotice.getVoice_name(), sendNotice.getSend_count(), sendNotice.getCompleteFileName(), sendNotice.getPush_url(), sendNotice.getTts_content(),
			    sendNotice.getVoice_type(), sendNotice.getDisplayNumber(), sendNotice.getSession_id(), sendNotice.getApp_key(), sendNotice.getCust_account(),
			    sendNotice.getPeriphery_code(), sendNotice.getBatch_number(), sendNotice.getMediaName() });

	    JSONObject obj = list.get(0);
	    result = obj.optInt("result");

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}
	return result;
    }

    /**
     * 按计费账号 group by 并且获取总数A
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @return
     */
    public List<JSONObject> queryCustAccountBySendNotice(CoreDao dao) {
	// 数据库连接
	Connection con = null;
	// 最后需返回的
	List<JSONObject> list = null;

	try {
	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");

	    // 因获取的数据库时间和实际时间有差异，因此获取当前服务系统时间
	    String pat1 = "yyyy-MM-dd HH:mm:ss";
	    SimpleDateFormat sdf1 = new SimpleDateFormat(pat1);
	    String thisDate = sdf1.format(new Date());

	    StringBuffer sql = new StringBuffer();
	    sql.append("select  cust_account,count(cust_account) count from t_send_notice where (status =-1 or (status = 1 and send_count<3)) and '" + thisDate
		    + "'>schedule_send_time and (run_thread is NULL or run_thread='')");
	    sql.append(" group by cust_account");
	    // 查询数据
	    list = dao.serviceJsonSql(con, sql.toString(), new Object[] { null });
	    // 将json类型转化为NumberPool

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}
	return list;
    }

    /**
     * 按计费账号 查询limit条数据
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @param cust_account
     * @param limit
     * @return
     */
    public List<SendNotice> querySendNoticeByCustAccount(CoreDao dao, String cust_account, int limit) {
	// 数据库连接
	Connection con = null;
	// 最后需返回的
	List<SendNotice> result = null;

	try {
	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");

	    // 因获取的数据库时间和实际时间有差异，因此获取当前服务系统时间
	    String pat1 = "yyyy-MM-dd HH:mm:ss";
	    SimpleDateFormat sdf1 = new SimpleDateFormat(pat1);
	    String thisDate = sdf1.format(new Date());
	    String nowAdd30Days = DateUtils.getTimeBeforeDays(-30);// 30天

	    StringBuffer sql = new StringBuffer();
	    sql.append("select * from t_send_notice where (status =-1 or (status = 1 and send_count<3)) and '" + thisDate
		    + "'>schedule_send_time and schedule_send_time > ? and (run_thread is NULL or run_thread='')");
	    sql.append("and cust_account=? ");
	    sql.append(" limit ? ");
	    // 查询数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] { nowAdd30Days, cust_account, limit });
	    // 将json类型转化为NumberPool
	    if (list != null) {
		List<SendNotice> items = dao.covertToBean(list, SendNotice.class);
		result = items;
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}
	return result;
    }

    /**
     * 语音通知单条更新线程号
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @param sendNotice
     * @return
     */
    public int updateRunThread(CoreDao dao, SendNotice sendNotice) {
	// 数据库连接
	Connection con = null;
	int result = -1;

	try {

	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 拼写SQL
	    StringBuffer sql = new StringBuffer(" UPDATE t_send_notice set run_thread=?");
	    sql.append(" where id=? ");
	    // 执行sql，更新相应数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] {

	    sendNotice.getRun_thread(), sendNotice.getId()

	    });

	    if (list != null && list.size() > 0) {
		JSONObject obj = list.get(0);
		result = obj.optInt("result");
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * 插入推送语音短信信息
     * 
     * 1.根据年月判断是否存在该表名； 2.若存在则将数据插入该年月表；若不存在则新建年月表后再插入该新表；(t_send_notice_??)
     * 3.根据session_id从t_send_notice表中删除这些数据
     * 
     * @deprecated 此功能暂不使用
     * @param dao
     * @param sendNotice
     * @param tableName
     * @return 成功返回0，失败返回-1
     */
    public int insertDateTable(CoreDao dao, SendNotice sendNotice, String tableName) {
	// 数据库连接
	Connection con = null;
	// 返回值
	int result = -1;

	try {
	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 开启事务管理
	    con.setAutoCommit(false);

	    // 插入语音短信信息，拼接sql
	    StringBuffer sql = new StringBuffer("INSERT INTO ");
	    sql.append(tableName);
	    sql.append("(meet_ims_id,callee,content,create_time,schedule_send_time,real_send_time,"
		    + "status,chargeNmr,chargeKey,note,voice_name,send_count,completeFileName,session_id,push_url,tts_content,voice_type,displayNumber,app_key,cust_account,periphery_code)");
	    sql.append(" VALUES(?,?,?,sysdate(),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

	    // 删除t_send_notice表中的该条语音短信信息，拼接sql
	    StringBuffer sqlDel = new StringBuffer("delete from t_send_notice t WHERE t.create_time<?");

	    // 执行插入语音短信信息的sql
	    List<JSONObject> list = dao.serviceJsonSql(
		    con,
		    sql.toString(),
		    new Object[] { sendNotice.getMeet_ims_id(), sendNotice.getCallee(), sendNotice.getContent(), sendNotice.getSchedule_send_time(),
			    sendNotice.getReal_send_time(), sendNotice.getStatus(), sendNotice.getChargeNmr(), sendNotice.getChargeKey(), sendNotice.getNote(),
			    sendNotice.getVoice_name(), sendNotice.getSend_count(), sendNotice.getCompleteFileName(), sendNotice.getSession_id(), sendNotice.getPush_url(),
			    sendNotice.getTts_content(), sendNotice.getVoice_type(), sendNotice.getDisplayNumber(), sendNotice.getApp_key(), sendNotice.getCust_account(),
			    sendNotice.getPeriphery_code() });

	    // 执行删除t_send_notice表中的该条语音短信信息的sql
	    dao.serviceJsonSql(con, sqlDel.toString(), new Object[] { sendNotice.getId() });

	    // 设置返回值
	    JSONObject obj = list.get(0);
	    result = obj.optInt("result");

	    // 执行成功，则进行提交
	    con.commit();

	} catch (Exception ex) {
	    ex.printStackTrace();

	    // 执行失败，则进行回滚操作
	    try {
		// DDL操作会自动提交而无法回滚，因此需要将该表删除
		con.rollback();
		// 删除表
		/*
		 * StringBuffer sqldrop = new StringBuffer("DROP TABLE ");
		 * sqldrop.append(tableName);
		 * log.info("---Rollback,drop the unused table:" +
		 * sqldrop.toString()); ps =
		 * con.prepareStatement(sqldrop.toString()); ps.executeUpdate();
		 */

	    } catch (SQLException e2) {
		e2.printStackTrace();
	    }
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * 批量插入/删除推送语音短信信息
     * 
     * @deprecated 此功能暂不使用 1.将数据插入该tableName年月表；(t_send_notice_yyyyMM)
     *             2.根据create_time从t_send_notice表中删除这些数据
     * 
     * @param dao
     * @param tableName
     * @param sendTime
     * @return 成功返回0，失败返回-1
     */
    public int insertDateTable(CoreDao dao, String tableName, String sendTime) {
	// 数据库连接
	Connection con = null;
	// 返回值
	int result = -1;

	try {
	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 开启事务管理
	    con.setAutoCommit(false);

	    // 插入语音短信信息，拼接sql
	    StringBuffer sql = new StringBuffer("INSERT INTO ");
	    sql.append(tableName);
	    sql.append(" SELECT * FROM t_send_notice WHERE schedule_send_time<?");

	    // 删除t_send_notice表中的这些语音短信信息，拼接sql
	    StringBuffer sqlDel = new StringBuffer("delete from t_send_notice WHERE schedule_send_time<?");

	    // 执行插入语音短信信息的sql
	    dao.serviceJsonSql(con, sql.toString(), new Object[] { sendTime });

	    // 执行删除t_send_notice表中的该条语音短信信息的sql
	    dao.serviceJsonSql(con, sqlDel.toString(), new Object[] { sendTime });

	    // 设置返回值
	    result = 0;

	    // 执行成功，则进行提交
	    con.commit();

	} catch (Exception ex) {
	    ex.printStackTrace();

	    // 执行失败，则进行回滚操作
	    try {
		con.rollback();
	    } catch (SQLException e2) {
		e2.printStackTrace();
	    }
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * 删除推送语音短信信息
     * 
     * @deprecated 此功能暂不使用
     * @param dao
     * @param id
     * @return 成功返回0，失败返回-1
     */
    public int delete(CoreDao dao, String id) {
	// 数据库连接
	Connection con = null;
	int result = -1;
	try {
	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 拼写sql
	    StringBuffer sql = new StringBuffer(" delete from t_send_notice where id =");
	    sql.append("?");

	    // 执行sql
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] { id });

	    if (list != null && list.size() > 0) {
		JSONObject obj = list.get(0);
		result = obj.optInt("result");
	    }
	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}
	return result;
    }

    /**
     * 更新语音通知发送状态 (发送成功或者失败时调用)
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @param sendNotice
     * @return 成功返回0，失败返回-1
     */
    public int updateStatus(CoreDao dao, SendNotice sendNotice) {
	// 数据库连接
	Connection con = null;
	int result = -1;

	try {

	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 拼写SQL
	    StringBuffer sql = new StringBuffer(" UPDATE t_send_notice set status=?");
	    sql.append(" where id=? ");
	    // 执行sql，更新相应数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] {

	    sendNotice.getStatus(), sendNotice.getId()

	    });

	    if (list != null && list.size() > 0) {
		JSONObject obj = list.get(0);
		result = obj.optInt("result");
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * 更新语音通知发送时间 (重发)
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @param sendNotice
     * @return
     */
    public int updateSendTime(CoreDao dao, SendNotice sendNotice) {
	// 数据库连接
	Connection con = null;
	int result = -1;

	try {

	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 拼写SQL
	    StringBuffer sql = new StringBuffer(" UPDATE t_send_notice set schedule_send_time=?");
	    sql.append(" where id=? ");
	    // 执行sql，更新相应数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] {

	    sendNotice.getSchedule_send_time(), sendNotice.getId()

	    });

	    if (list != null && list.size() > 0) {
		JSONObject obj = list.get(0);
		result = obj.optInt("result");
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * 根据语音文件名称更新 语音通知状态,备注,已发送条数(语音文件上传失败后调用)
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @param status
     * @param note
     * @param mediaName
     * @return
     */
    public int updateSendVoice(CoreDao dao, String status, String note, String mediaName) {
	// 数据库连接
	Connection con = null;
	int result = -1;

	try {

	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 拼写SQL
	    StringBuffer sql = new StringBuffer(" UPDATE t_send_notice set status=?,send_count=?,note=?");
	    sql.append(" where mediaName=? ");
	    // 执行sql，更新相应数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] { status, 3, note, mediaName

	    });

	    if (list != null && list.size() > 0) {
		JSONObject obj = list.get(0);
		result = obj.optInt("result");
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * 更新语音文件名称 (语音文件上传成功后调用)
     * 
     * @param dao
     * @author gaoxs @ Date 2016-12-29
     * @param voice_name
     * @param mediaName
     * @return
     */
    public int updateVoice_name(CoreDao dao, String voice_name, String mediaName) {
	// 数据库连接
	Connection con = null;
	int result = -1;

	try {

	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 拼写SQL
	    StringBuffer sql = new StringBuffer(" UPDATE t_send_notice set voice_name=?");
	    sql.append(" where mediaName=? and status !='0'");
	    // 执行sql，更新相应数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] {

	    voice_name, mediaName

	    });

	    if (list != null && list.size() > 0) {
		JSONObject obj = list.get(0);
		result = obj.optInt("result");
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * 更新语音通知 已发送条数,备注 (发送失败后调用)
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @param sendNotice
     * @return
     */
    public int updateSendCount(CoreDao dao, SendNotice sendNotice) {
	// 数据库连接
	Connection con = null;
	int result = -1;

	try {
	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 拼写SQL
	    StringBuffer sql = new StringBuffer(" UPDATE t_send_notice set send_count=?,note=?");
	    sql.append(" where id=? ");
	    // 执行sql，更新相应数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] {

	    sendNotice.getSend_count(), sendNotice.getNote(), sendNotice.getId()

	    });

	    if (list != null && list.size() > 0) {
		JSONObject obj = list.get(0);
		result = obj.optInt("result");
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * 更新语音通知 sessionID (发送成功后调用)
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @param sendNotice
     * @return
     */
    public int updateSessionId(CoreDao dao, SendNotice sendNotice) {
	// 数据库连接
	Connection con = null;
	int result = -1;

	try {

	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 拼写SQL
	    StringBuffer sql = new StringBuffer(" UPDATE t_send_notice set session_id=?");
	    sql.append(" where id=? ");
	    // 执行sql，更新相应数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] {

	    sendNotice.getSession_id(), sendNotice.getId()

	    });

	    if (list != null && list.size() > 0) {
		JSONObject obj = list.get(0);
		result = obj.optInt("result");
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * 语音通知批量更新线程号
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @param sendNotice
     * @return
     */
    public int updateAllRunThread(CoreDao dao) {
	// 数据库连接
	Connection con = null;
	int result = -1;

	try {
	    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    Date now = new Date();
	    Date nowAdd = new Date(now.getTime() - 30 * 60 * 1000);// 30分钟
	    String nowAdd30Days = DateUtils.getTimeBeforeDays(-30);// 30天
	    String schedule_send_time = format.format(nowAdd);
	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 拼写SQL
	    StringBuffer sql = new StringBuffer(" UPDATE t_send_notice set run_thread=''");
	    sql.append(" where schedule_send_time<? and schedule_send_time>? and run_thread != ''");
	    // 执行sql，更新相应数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] { schedule_send_time, nowAdd30Days });

	    if (list != null && list.size() > 0) {
		JSONObject obj = list.get(0);
		result = obj.optInt("result");
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * 取消语音通知发送
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @param sendNotice
     * @return
     */
    public int updateSendTime2(CoreDao dao, SendNotice sendNotice) {
	// 数据库连接
	Connection con = null;
	int result = -1;

	try {

	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 拼写SQL
	    StringBuffer sql = new StringBuffer(" UPDATE t_send_notice set status='3'");
	    sql.append(" where app_key=? and cust_account=?  and status='-1' ");
	    if (StringUtils.isNotBlank(sendNotice.getBatch_number())) {
		sql.append(" and batch_number='" + sendNotice.getBatch_number() + "'");
	    }
	    if (sendNotice.getMeet_ims_id() > 0) {
		sql.append(" and meet_ims_id=" + sendNotice.getMeet_ims_id());
	    }
	    if(StringUtils.isNotBlank(sendNotice.getSession_id())){
		sql.append(" and session_id='"+sendNotice.getSession_id()+ "'");
	    }
	    // System.out.println(sql.toString());
	    // 执行sql，更新相应数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] {

	    sendNotice.getApp_key(), sendNotice.getCust_account()

	    });

	    if (list != null && list.size() > 0) {
		JSONObject obj = list.get(0);
		result = obj.optInt("result");
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}

	return result;
    }

    /**
     * @deprecated 老版语音通知发送获取方式
     * @param dao
     * @return
     */
    public List<SendNotice> queryAllNumber(CoreDao dao) {
	// log.info("SendNotice.queryAllSendNotice");
	// 数据库连接
	Connection con = null;
	// 最后需返回的
	List<SendNotice> result = null;

	try {
	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");
	    // 因获取的数据库时间和实际时间有差异，因此获取当前服务系统时间
	    String pat1 = "yyyy-MM-dd HH:mm:ss";
	    SimpleDateFormat sdf1 = new SimpleDateFormat(pat1);
	    String thisDate = sdf1.format(new Date());

	    StringBuffer sql = new StringBuffer();
	    sql.append("select t.*,-1 cid from t_send_notice t where (t.status =-1 or (t.status = 1 and t.send_count<3)) and '" + thisDate
		    + "'>t.schedule_send_time and (t.run_thread is NULL or t.run_thread='')");
	    sql.append(" limit 100 ");
	    sql.append(" union ");
	    sql.append("select t.*,ifnull(ifc.id,-1) cid from t_send_notice t ");
	    sql.append("left join t_infocontrol ifc on ifc.app_key=t.app_key and ifc.batch_number=t.batch_number and ifc.cust_account=t.cust_account and ifc.status='0' and ifc.ability_type=t.voice_type ");
	    sql.append("where t.status='2'  and (t.run_thread is NULL or t.run_thread='') and t.schedule_send_time<'").append(thisDate).append("'");
	    sql.append(" limit 100 ");
	    // log.info("queryAllSendNotice="+sql);
	    // 查询数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] { null });
	    // 将json类型转化为NumberPool
	    if (list != null) {
		List<SendNotice> items = dao.covertToBean(list, SendNotice.class);
		result = items;
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}
	return result;

    }

    private int getLimitAmount() {
	String redisKey = "voiceNotice:sendJob:limit:amount"; // redis主键voiceNotice:sendJob:limit:amount
	String limitAmount = RedisUtil.getString(redisKey); // 从redis获取阀值
	if (StringUtils.isBlank(limitAmount)) { // 从redis获取阀值失败

	}

	return Integer.valueOf(limitAmount);
    }

    /**
     * 根据meetId获取相应语音通知信息
     * 
     * @author gaoxs @ Date 2016-12-29
     * @param dao
     * @param meetId
     * @return
     */
    public SendNotice querySendNoticeByMeetId(CoreDao dao, String meetId) {
	// 数据库连接
	Connection con = null;
	// 最后需返回的
	List<SendNotice> result = null;

	SendNotice resuleSendNotice = null;

	try {
	    // 获取数据库连接
	    con = DBConnectionUtil.getDBConnection("emate1");

	    StringBuffer sql = new StringBuffer();
	    sql.append("SELECT * FROM t_send_notice WHERE meet_ims_id=?");
	    // 查询数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] { meetId });
	    // 将json类型转化为NumberPool
	    if (list != null) {
		List<SendNotice> items = dao.covertToBean(list, SendNotice.class);
		result = items;
		if (result.size() > 0) {
		    resuleSendNotice = result.get(0);
		}
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}
	return resuleSendNotice;
    }

    /**
     * 查询本模式下是否存在该t_send_notice年月表
     * 
     * @deprecated 暂不使用
     * @param dao
     * @param tableName
     * @return
     */
    public int queryPushNoticeInfoTable(CoreDao dao, String tableName) {

	Connection con = null;
	int result = -1;
	try {
	    con = DBConnectionUtil.getDBConnection("emate1");
	    StringBuffer sql = new StringBuffer(
		    "SELECT COUNT(TABLE_NAME) AS id FROM information_schema.`TABLES` WHERE table_schema='voip_plat_version3' AND table_type='base table'");
	    sql.append(" AND TABLE_NAME=?");

	    // 查询数据
	    List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(), new Object[] { tableName });
	    if (list != null && list.size() > 0) {
		List<ParamBean> items = dao.covertToBean(list, ParamBean.class);
		ParamBean bean = items.get(0);
		result = Integer.parseInt(bean.getId());
	    }

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}
	return result;
    }

    /**
     * 根据表名称创建新的语音短信基本表
     * 
     * @deprecated 暂不使用
     * @param dao
     * @param tableName
     * @return
     */
    public int createNewPushNoticeInfoTable(CoreDao dao, String tableName) {

	Connection con = null;
	PreparedStatement ps = null;
	int result = -1;
	try {
	    con = DBConnectionUtil.getDBConnection("emate1");
	    StringBuffer sql = new StringBuffer("CREATE TABLE ");
	    sql.append(tableName);
	    sql.append(" LIKE t_send_notice;");

	    // 执行sql语句
	    ps = con.prepareStatement(sql.toString());
	    ps.executeUpdate();

	    // 如果年月表新建成功，则设置为1
	    result = 1;

	} catch (Exception ex) {
	    ex.printStackTrace();
	} finally {
	    DBConnectionUtil.close(null, null, con);
	}
	return result;
    }

}
